﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Demo.FolderOp
{
    public partial class IMGOperate : Form
    {
        public IMGOperate()
        {
            InitializeComponent();
        }

        private void btnSourseSelectFloder_Click(object sender, EventArgs e)
        {
            DialogResult dr = this.folderBrowserDialog.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                this.txtWhereFloderUrl.Text = folderBrowserDialog.SelectedPath;
            }
        }

        private void btnTargetDialogUrl_Click(object sender, EventArgs e)
        {
            DialogResult dr = this.targetFolderBrowserDialog.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                this.txtTargetSiteUrl.Text = targetFolderBrowserDialog.SelectedPath;
            }
        }

        private void btnGetImg_Click(object sender, EventArgs e)
        {
            //检查地址是否正确
            if (this.txtWhereFloderUrl.Text == "" || this.txtTargetSiteUrl.Text == "")
            {
                MessageBox.Show("请选择地址！");
            }

            List<string> myFilterList = new List<string>();
            string tempFilter = this.txtFilter.Text.Trim();
            if (!string.IsNullOrWhiteSpace(tempFilter))
            {
                myFilterList = tempFilter.Split('|').ToList();
            }
            else
            {
                myFilterList.AddRange(new string[] { ".jpg", ".gif", ".png", ".webp" });
            }

            int tempMinSize = 20; //图片文件 默认 >= 20KB 才能复制
            if (!string.IsNullOrWhiteSpace(this.txtMinImgSize.Text))
            {
                try
                {
                    tempMinSize = Convert.ToInt32(this.txtMinImgSize.Text);
                }
                catch (Exception ex)
                {
                }
            }

            //初始化
            FileMethod.InitFileMethod();
            if (FileMethod.GetImgInfo(this.txtWhereFloderUrl.Text, this.txtTargetSiteUrl.Text, myFilterList, tempMinSize))
            {
                CommonForm.ShowMessage("复制成功");
            }
            else
            {
                CommonForm.ShowMessage("复制失败", 2);
            }

        }
    }
}
